project(
  opengl_demo
  LANGUAGES CXX C
)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC_SEARCH_PATHS "ui")

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(Qt5 COMPONENTS Widgets REQUIRED)

add_subdirectory(depends/qrender)

set(_srcs
    src/qls_opengl_demo.cpp
    src/qls_opengl_demo_service.cpp
    src/render_form.cpp
    src/dice_renderer.cpp
    src/math.cpp
)

set(_headers
    include/opengl_demo/qls_opengl_demo.h
    include/opengl_demo/qls_opengl_demo_service.h
    include/opengl_demo/render_form.h
    src/dice_renderer.h
    src/math.h
)

set(_ui
    ui/qls_opengl_demo.ui
    ui/render_form.ui
)

add_library(${PROJECT_NAME} SHARED ${_srcs} ${_headers} ${_ui})
target_link_libraries(${PROJECT_NAME} PUBLIC
    themes_manager log settings
    plugins_manager_appfwk qrender
    Qt5::Widgets Qt5::Core
)
target_include_directories(${PROJECT_NAME} PUBLIC include)

file(MAKE_DIRECTORY ${LIBRARY_OUTPUT_PATH}/plugins/QCoreSystem/)

if(UNIX)
    add_custom_command(
        TARGET ${PROJECT_NAME} POST_BUILD
        COMMAND ${CMAKE_COMMAND} -E create_symlink
        ${LIBRARY_OUTPUT_PATH}/lib${PROJECT_NAME}.so ${LIBRARY_OUTPUT_PATH}/plugins/QCoreSystem/lib${PROJECT_NAME}.so
    )
elseif(WIN32)
    add_custom_command(
        TARGET ${PROJECT_NAME} POST_BUILD
        COMMAND ${CMAKE_COMMAND} -E create_symlink
        ${LIBRARY_OUTPUT_PATH}/lib${PROJECT_NAME}.dll ${LIBRARY_OUTPUT_PATH}/plugins/QCoreSystem/lib${PROJECT_NAME}.dll
    )
endif()
